import { useRef, useState } from 'react';
import { DefaultProps, RectConfigCustom, WidgetCustomGroup } from '../types';

export const useGetDefaultProps = ({
  name,
  defaultData,
  defaultAttribute,
}: {
  name: string;
  defaultData: any;
  defaultAttribute: WidgetCustomGroup;
}): DefaultProps => {
  //用于模拟数据调试
  const [widgetData] = useState(defaultData);
  const ref = useRef({
    customEvent: (type: string, data?: any) => {
      console.log('事件类型：', type);
      console.log('事件传递参数：', data);
    },
  });
  const initCustomAttribute: (data: any, rect?: RectConfigCustom) => void = (
    data,
    rect,
  ) => {
    console.log('初始化自定义属性：', data);
    console.log('初始化位置：', rect);
  };
  const initCustomEventList: (data: any) => void = (data) => {
    console.log('初始化事件列表：', data);
  };
  const initStaticDataOrigin: (data: any) => void = (data) => {
    console.log('初始化数据：', data);
  };
  const onWidgetUpdate: (widget: any) => void = (data) => {
    console.log('更新组件配置', data);
  };
  return {
    widget: {
      config: {
        customAttribute: defaultAttribute,
        version: '1.0.0',
        widgetVersion: '1.0.0',
        type: 'media',
        originalType: '',
        index: 15,
        name: name,
        linkageConfig: {
          open: false,
          chartGroupColumns: [],
        },
        autoUpdate: false,
        lock: false,
        frequency: 60,
        rect: {
          x: 0,
          y: 0,
          width: 340,
          height: 700,
        },
        background: {
          color: 'transparent',
          image: '',
          size: '100% 100%',
          repeat: 'no-repeat',
        },
        border: {
          color: '',
          width: 0,
          style: 'solid',
          radius: 0,
        },
        content: {
          type: 'test',
        },
        hide: false,
        nameConfig: {
          fontFamily:
            '-apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
          fontSize: '14',
          fontWeight: 'normal',
          fontStyle: 'normal',
          color: '#181C32',
          show: true,
          textAlign: 'left',
        },
        padding: {
          top: 0,
          bottom: 0,
          left: 0,
          right: 0,
        },
        dataOrigin: {
          dataStore: {
            name: '',
          },
          type: 'static',
          static: '',
          api: {
            url: '',
            method: 'GET',
            callbackName: 'data',
            callbackDefault: '',
            header: '{}',
            params: '{}',
            useFilter: false,
            filterValue: 'return data;',
          },
          websocket: {
            url: '',
            callbackName: 'data',
            callbackDefault: '',
            header: '',
            message: '',
            useFilter: false,
            filterValue: 'return data;',
            useFilterPath: false,
            pathField: '',
            pathValue: '',
            pathMode: 'fuzzy',
          },
          databox: {
            useFilter: false,
            filterValue: 'return data;',
          },
          dataview: {
            id: '',
            params: '{}',
            useFilter: false,
            filterValue: 'return data;',
          },
        },
        eventList: [
          {
            type: 'onClick',
            condition: {
              type: '&',
            },
            actions: [
              {
                action: 'custom',
                on: [],
                animate: {
                  type: 'animate__none__xx',
                  time: 600,
                  delay: 0,
                },
                customJs: '',
                filterJs: '',
                showWindow: {
                  url: '',
                  type: '1',
                  filterJs: '',
                },
                hideWindow: {
                  type: '1',
                },
                showCustomWindow: {
                  id: '',
                  url: '',
                  offsetX: 470,
                  offsetY: 120,
                  width: 960,
                  height: 800,
                  draggbale: false,
                  resize: false,
                  filterJs: '',
                },
                hideCustomWindow: {},
              },
            ],
          },
        ],
        icon: '',
      },
      id: '00a4e0035cd245bc8157c924f85a20f7',
      parentId: '',
      projectId: 'dd36a2e341af453795db797b7ff7cd41',
      type: null,
    },
    widgetData,
    initCustomAttribute,
    initCustomEventList,
    initStaticDataOrigin,
    widgetRef: ref,
    onWidgetUpdate,
  };
};
